# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-term
pkgver=0.07
_rockver=0.7-1
pkgrel=2
pkgdesc="Terminal operations for Lua"
url="https://github.com/hoelzro/lua-term"
arch="all"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/hoelzro/lua-term/archive/$pkgver.tar.gz"
options="!check"  # upstream does not provide tests

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make -C "$builddir-$lver" LUA_VER=$lver CFLAGS="$CFLAGS"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$pkgname/$_rockver"

	cd "$builddir-$lver"
	make LUA_VER=$lver LUA_DIR="$subpkgdir/usr" install

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="2046ba1861ff590c191bb651941c45eb8b6e9a1252b05e78daaeb31837ce1fc7da9ba124aec34dc7842fd304e945754c463ffd75941125ff952e911ba66efa31  lua-term-0.07.tar.gz"
